What is vscode-languageserver-types?
The vscode-languageserver-types package provides data types used by the Visual Studio Code language server protocol. It helps in the development of language servers that can be integrated with editors supporting the protocol, enabling features like auto-completion, go-to-definition, or syntax highlighting.
What are vscode-languageserver-types's main functionalities?
Position and Range
Defines positions and ranges within a text document. Positions are zero-based and determine a point in a document by line and character offset. Ranges define a portion of text between two positions.
{ Position, Range } = require('vscode-languageserver-types');
let startPosition = Position.create(1, 5);
let endPosition = Position.create(1, 10);
let range = Range.create(startPosition, endPosition);
Text Edits
Allows for the creation of text edits, which are used to represent changes to a text document. These can be used to manipulate text by inserting, replacing, or deleting text in a document.
{ TextEdit } = require('vscode-languageserver-types');
let edit = TextEdit.replace(Range.create(Position.create(0, 0), Position.create(0, 10)), 'new text');
Diagnostics
Supports diagnostics, which are problems found in the code such as syntax errors or warnings. Diagnostics are associated with a range in the document and can have severities like Error, Warning, etc.
{ Diagnostic, Range, DiagnosticSeverity } = require('vscode-languageserver-types');
let diagnostic = Diagnostic.create(Range.create(Position.create(1, 0), Position.create(1, 1)), 'Syntax error', DiagnosticSeverity.Error, undefined, 'my-linter');
Other packages similar to vscode-languageserver-types
vscode-languageserver
While vscode-languageserver-types provides the data types for language server implementations, vscode-languageserver is a more comprehensive package that includes the full server-side implementation of the Language Server Protocol. It uses the types from vscode-languageserver-types and provides additional utilities for managing communication between a server and client.
monaco-languages
Similar to vscode-languageserver-types, monaco-languages is used in the Monaco Editor (the editor that powers VS Code) to support various language features. However, it is tailored specifically for the Monaco Editor's architecture and may not be directly compatible with other editors or IDEs.